﻿using EmoneyWeiXinCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ActivtyUI.Filter
{
    public class WeiXinUserAgentFilter : System.Web.Mvc.AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["isFiltUserAgent"] == "1")
            {
                if (!httpContext.Request.UserAgent.ToLower().Contains("micromessenger"))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return true;
            }

        }

        protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext)
        {
            filterContext.Result = new RedirectResult(Config.Host_Url3 + "Common/ErrorPage?msg=" + "uaErr");
            //base.HandleUnauthorizedRequest(filterContext);
        }
    }
}